<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
	  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	  layout:decorate="~{layouts/layout}">
  <head>
    <meta charset="utf-8">
    <title>新增电子病历</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<script>
	  function saveMr() {
		  debugger
		  var data = $("#emr-form").serializeJson();
		  var patients = selectSelects("patients");
		  data.visitCardNo = patients.split("_")[0];
		  data.patientName = patients.split("_")[1];
		  var emrTemplates = selectSelects("emrTemplates");
		  data.type = emrTemplates.split("_")[0];
		  data.templateId = emrTemplates.split("_")[1];
		  data.department = selectSelects("depts");
		  console.log("data: ", data)
		  $.ajax({
			  url: "mr/save",
			  type: "post",
			  contentType: "application/json",
			  dataType: "json",
			  data: JSON.stringify(data),
			  beforeSend: function () {},
			  success: function(result) {
				  console.log("result: ", result);
				  const msg = EmrResultCode.getMessageByCode(result.code, result.msg);
				  if (result.code === 200){
					  alert(msg);
				  }else {
					  alert(msg);
				  }

			  }
		  })
	  }
	</script>
  </head>

  <body>
	<th:block layout:fragment="content">
		<div class="span9">
			<div class="row-fluid">
				<div class="page-header">
					<h1>新增电子病历</h1>
				</div>
				<form id="emr-form" class="form-horizontal">
					<fieldset>
						<div class="control-group">
							<div class="form-group">
								<label class="control-label" for="patients">病 人</label>
								<div class="controls">
									<select id="patients">
										<option value=""></option>
										<option value="1_张三">张三</option>
										<option value="2_李四">李四</option>
									</select>
								</div>
							</div>
						</div>
						<div class="control-group">
							<div class="form-group">
								<label class="control-label" for="emrTemplates">病历模板</label>
								<div class="controls">
									<select id="emrTemplates">
										<option th:each="template:${emrTemplateList}"
												th:value="${template.type} + '_' + ${template.id}"
												th:text="${template.title} + '_' + (${template.allowMultiple} == 0 ? '单例' : '多例')">
										</option>
									</select>
								</div>
							</div>
						</div>
						<div class="control-group">
							<div class="form-group">
								<label class="control-label" for="depts">部 门</label>
								<div class="controls">
									<select id="depts">
										<option value=""></option>
										<option value="胃肠中心">胃肠中心</option>
										<option value="肺癌中心">肺癌中心</option>
									</select>
								</div>
							</div>
						</div>
					</fieldset>
				</form>
				<div class="form-actions">
					<input type="submit" class="btn btn-success btn-large" value="保存病历" onclick="saveMr()" /> <a class="btn" th:href="@{/emr-list}">Cancel</a>
				</div>
			</div>
		</div>
	</th:block>
  </body>
</html>
